import 'package:xinxuan/vo/activities_list_vo.dart';
import 'package:xinxuan/vo/address_list_vo.dart';
import 'package:xinxuan/vo/advert_vo.dart';
import 'package:xinxuan/vo/ali_pay_vo.dart';
import 'package:xinxuan/vo/announcements_vo.dart';
import 'package:xinxuan/vo/article_detail_vo.dart';
import 'package:xinxuan/vo/articles_list_vo.dart';
import 'package:xinxuan/vo/authentication_vo.dart';
import 'package:xinxuan/vo/bank_card_add_edit_vo.dart';
import 'package:xinxuan/vo/bank_card_list_vo.dart';
import 'package:xinxuan/vo/banner_list_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_activity_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_activity_products_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_order_detail_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_order_list_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_products_detail_vo.dart';
import 'package:xinxuan/vo/blindbox/blindbox_submit_order_vo.dart';
import 'package:xinxuan/vo/categoires_list_vo.dart';
import 'package:xinxuan/vo/create_seckill_order_vo.dart';
import 'package:xinxuan/vo/displacement_list_vo.dart';
import 'package:xinxuan/vo/entrust_vo.dart';
import 'package:xinxuan/vo/features_list_vo.dart';
import 'package:xinxuan/vo/gift_list_vo.dart';
import 'package:xinxuan/vo/gift_order_detail_vo.dart';
import 'package:xinxuan/vo/gift_order_list_vo.dart';
import 'package:xinxuan/vo/good_detail_vo.dart';
import 'package:xinxuan/vo/identities_vo.dart';
import 'package:xinxuan/vo/integral_detail_vo.dart';
import 'package:xinxuan/vo/integral_list_vo.dart';
import 'package:xinxuan/vo/logistics_vo.dart';
import 'package:xinxuan/vo/msg_vo.dart';
import 'package:xinxuan/vo/news_list_vo.dart';
import 'package:xinxuan/vo/order_detail_vo.dart';
import 'package:xinxuan/vo/order_pay_status_vo.dart';
import 'package:xinxuan/vo/pay_verification_vo.dart';
import 'package:xinxuan/vo/products_list_vo.dart';
import 'package:xinxuan/vo/receive_user_list_vo.dart';
import 'package:xinxuan/vo/seckill_activity_products_detail_vo.dart';
import 'package:xinxuan/vo/seckill_activity_products_vo.dart';
import 'package:xinxuan/vo/seckill_detail_vo.dart';
import 'package:xinxuan/vo/seckill_holder_products_detail_vo.dart';
import 'package:xinxuan/vo/seckill_holder_products_vo.dart';
import 'package:xinxuan/vo/seckill_list_vo.dart';
import 'package:xinxuan/vo/seckill_my_commodity_list_vo.dart';
import 'package:xinxuan/vo/seckill_recovery_vo.dart';
import 'package:xinxuan/vo/seckill_substitute_prices_vo.dart';
import 'package:xinxuan/vo/sign_record_vo.dart';
import 'package:xinxuan/vo/sign_vo.dart';
import 'package:xinxuan/vo/store_list_vo.dart';
import 'package:xinxuan/vo/store_order_list_vo.dart';
import 'package:xinxuan/vo/store_time_list_vo.dart';
import 'package:xinxuan/vo/submit_order_vo.dart';
import 'package:xinxuan/vo/submit_seckill_order_vo.dart';
import 'package:xinxuan/vo/system_address_list_vo.dart';
import 'package:xinxuan/vo/system_bank_and_auth_list_vo.dart';
import 'package:xinxuan/vo/system_bank_list_vo.dart';
import 'package:xinxuan/vo/team_members_vo.dart';
import 'package:xinxuan/vo/team_spaces_vo.dart';
import 'package:xinxuan/vo/upload_image_vo.dart';
import 'package:xinxuan/vo/user_data_vo.dart';
import 'package:xinxuan/vo/user_login_vo.dart';
import 'package:xinxuan/vo/verification_vo.dart';
import 'package:xinxuan/vo/version_vo.dart';
import 'package:xinxuan/vo/withdrawal_list_vo.dart';
import 'package:xinxuan/vo/writeoff_vo.dart';
import 'package:xinxuan/vo/wx_pay_vo.dart';
import 'package:dio/dio.dart';

import 'http_util.dart';

class HttpUtilService {

  /// 获取验证码
  static Future<VerificationVo?> getVerificationCode({ required String mobile, required String type, bool loading = true }) async {
    Map<String, dynamic> param = {
      'mobile': mobile,
      'type': type,
    };
    return VerificationVo.fromJson(await HttpUtil.instance.get('/system/verification/codes', data: param, loading: loading));
  }
  
  /// 验证码登录
  static Future<UserLoginVo> verificationCodeLogin({ required String mobile, required String verificationCode, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'mobile': mobile,
      'verification_code': verificationCode,
      'verification_key': verificationKey,
    };
    return UserLoginVo.fromJson(await HttpUtil.instance.post('/auth/login', data: param, loading: loading));
  }
  
  /// 密码登录
  static Future<UserLoginVo> passwordLogin({ required String mobile, required String password, bool loading = true }) async {
    Map<String, dynamic> param = {
      'mobile': mobile,
      'password': password,
    };
    return UserLoginVo.fromJson(await HttpUtil.instance.post('/auth/login', data: param, loading: loading));
  }
  
  /// 获取用户信息
  static Future<UserDataVo> getUserInfo({ bool loading = true }) async {
   return UserDataVo.fromJson(await HttpUtil.instance.get('/user/users/me', loading: loading));
  }

  /// 获取分类列表
  static Future<CategoiresListVo> getCategoiresList({ bool loading = true }) async {
    return CategoiresListVo.fromJson(await HttpUtil.instance.get('/product/categoires', loading: loading));
  }
  
  /// 获取首页banner
  static Future<BannerListVo> getBannersList({ bool loading = true }) async {
    return BannerListVo.fromJson(await HttpUtil.instance.get('/system/banners', loading: loading));
  }
  
  /// 获取首页活动
  static Future<ActivitiesListVo> getActivitiesList({ bool loading = true }) async {
    return ActivitiesListVo.fromJson(await HttpUtil.instance.get('/activity/activities', loading: loading));
  }
  
  /// 获取商品列表(搜索)
  static Future<ProductsListVo> getProductsList({ required String orderType, required String sort, int categoryId = 0, String keyword = '', int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'keyword': keyword,
      'order_type': orderType,
      'sort': sort,
      'category_id': categoryId,
    };
    return ProductsListVo.fromJson(await HttpUtil.instance.get('/product/products', data: param, loading: loading));
  }
  
  /// 获取活动商品列表
  static Future<ProductsListVo> getActivityGoodList({ required int activityId, required String orderType, required String sort, String keyword = '', int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'keyword': keyword,
      'order_type': orderType,
      'sort': sort,
      'activity_id': activityId
    };
    return ProductsListVo.fromJson(await HttpUtil.instance.get('/activity/products', data: param, loading: loading));
  }
  
  /// 首页精选好物
  static Future<FeaturesListVo> getFeaturesList({ required int typeId, int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'category_id': typeId
    };
    return FeaturesListVo.fromJson(await HttpUtil.instance.get('/product/features', data: param, loading: loading));
  }
  
  /// 首页公告
  static Future<NewsListVo> getNewsList({ bool loading = true }) async {
    return NewsListVo.fromJson(await HttpUtil.instance.get('/system/news', loading: loading));
  }
  
  /// 获取商品详情
  static Future<GoodDetailVo> getGoodDetail({ required int goodId, bool loading = true }) async {
    return GoodDetailVo.fromJson(await HttpUtil.instance.get('/product/products/$goodId', loading: loading));
  }
  
  /// 各种文章列表，categoryId 可写死
  static Future<ArticlesListVo> getArticlesList({ required int categoryId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'category_id': categoryId
    };
    return ArticlesListVo.fromJson(await HttpUtil.instance.get('/article/articles', data: param, loading: loading));
  }
  
  /// 获取文章详情
  static Future<ArticleDetailVo> getArticleDetail({ required int articleId, bool loading = true }) async {
    return ArticleDetailVo.fromJson(await HttpUtil.instance.get('/article/articles/$articleId', loading: loading));
  }
  
  /// 修改用户信息
  static Future<UserDataVo> editUser({ required Map<String, dynamic> param, bool loading = true }) async {
    return UserDataVo.fromJson(await HttpUtil.instance.post('/user/users', data: param, loading: loading));
  }

  /// 修改密码
  static Future<bool> editPassword({ required String verificationCode, required String password, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'verification_code': verificationCode,
      'password': password,
      'verification_key': verificationKey,
    };
    var res = await HttpUtil.instance.post('/user/login/passwords', data: param, loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }

  // /// 获取实名认证信息
  // static Future<AuthenticationVo> getAuthenticationData({ bool loading = true }) async {
  //   return AuthenticationVo.fromJson(await HttpUtil.instance.get('/user/identities', loading: loading));
  // }

  /// 实名认证
  static Future<AuthenticationVo> userAuthentication({ required String realname, required String number, required String imageIds, bool loading = true }) async {
    Map<String, dynamic> param = {
      'realname': realname,
      'number': number,
      'image_ids': imageIds,
    };
    return AuthenticationVo.fromJson(await HttpUtil.instance.post('/user/identities', data: param, loading: loading));
  }


  /// 获取系统银行卡
  static Future<SystemBankListVo> getSystemBankList({ bool loading = true }) async {
    return SystemBankListVo.fromJson(await HttpUtil.instance.get('/system/banks', loading: loading));
  }
  
  /// 获取银行卡列表
  static Future<BankCardListVo> getBankCardList({ int type = 0, bool loading = true }) async {
    Map<String, dynamic> param = {
      'type': type
    };
    return BankCardListVo.fromJson(await HttpUtil.instance.get('/user/payments', data: param, loading: loading));
  }

  /// 添加银行卡
  static Future<BankCardAddEditVo> addBankCard({ required int paymentId, required int isDefault, String password = '', required String verificationCode, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'verification_code': verificationCode,
      'payment_id': paymentId,
      'is_default': isDefault,
      'password': password,
      'verification_key': verificationKey,
    };
    return BankCardAddEditVo.fromJson(await HttpUtil.instance.post('/user/payments', data: param, loading: loading));
  }

  /// 修改银行卡
  static Future<bool> editBankCard({ required int id, required String accountName, required String cardNumber, required int isDefault, required int bankId, required String verificationCode, required String identityNumber, required String verificationKey, int type = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'account_name': accountName,
      'card_number': cardNumber,
      'is_default': isDefault,
      'bank_id': bankId,
      'verification_code': verificationCode,
      'identity_number': identityNumber,
      'verification_key': verificationKey,
    };
    var res = await HttpUtil.instance.put('/user/payments/$id', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 删除银行卡
  static Future<bool> delBankCard({ required int id, bool loading = true }) async {
    var res = await HttpUtil.instance.del('/user/payments/$id', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 邀请加入
  static Future<bool> invitations({ required String invitationCode, bool loading = true }) async {
    Map<String, dynamic> param = {
      'invitation_code': invitationCode
    };
    var res = await HttpUtil.instance.post('/user/invitations', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 获取系统地址列表
  static Future<SystemAddressListVo> getSystemRegions({ int parentId = 0, bool loading = true }) async {
    Map<String, dynamic> param = {
      'parent_id': parentId
    };
    return SystemAddressListVo.fromJson(await HttpUtil.instance.get('/system/regions', data: param, loading: loading));
  }

  /// 获取收货地址列表
  static Future<AddressListVo> getAddressList({ bool loading = true }) async {
    return AddressListVo.fromJson(await HttpUtil.instance.get('/user/addresses', loading: loading));
  }

  /// 添加收货地址
  static Future<bool> addAddress({ required Map<String, dynamic> map, bool loading = true }) async {
    var res = await HttpUtil.instance.post('/user/addresses', data: map, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 修改收货地址
  static Future<bool> editAddress({ required int id, required Map<String, dynamic> map, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/user/addresses/$id', data: map, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 删除收货地址
  static Future<bool> delAddress({ required int id, bool loading = true }) async {
    var res = await HttpUtil.instance.del('/user/addresses/$id', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 提交反馈
  static Future<bool> submitFeedback({ required String content, required String contact, bool loading = true }) async {
    Map<String, dynamic> param = {
      'content': content,
      'contact': contact,
    };
    var res = await HttpUtil.instance.post('/user/feedbacks', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 提交会员申请
  static Future<bool> submitUpgrades({ required String reason, bool loading = true }) async {
    Map<String, dynamic> param = {
      'reason': reason,
    };
    var res = await HttpUtil.instance.post('/user/upgrades', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 检查版本
  static Future<VersionVo> checkVersion({ bool loading = true }) async {
    return VersionVo.fromJson(await HttpUtil.instance.get('/system/versions/latest', loading: loading));
  }
  
  /// 提交商城订单
  static Future<SubmitOrderVo> submitStoreOrder({ required int productId, required int skuId, required int quantity, required int addressId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'product_id': productId,
      'sku_id': skuId,
      'quantity': quantity,
      'address_id': addressId,
    };
    return SubmitOrderVo.fromJson(await HttpUtil.instance.post('/order/orders', data: param, loading: loading));
  }
  
  /// 获取商城订单详情
  static Future<OrderDetailVo> getStoreOrderDetail({ required int orderId, bool loading = true }) async {
    return OrderDetailVo.fromJson(await HttpUtil.instance.get('/order/orders/$orderId', loading: loading));
  }
  
  /// 获取抢购商品列表
  static Future<SeckillListVo> getSeckillList({ required int page, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return SeckillListVo.fromJson(await HttpUtil.instance.get('/seckill/holder/seckills', data: param, loading: loading));
  }
  
  /// 获取抢购商品详情
  static Future<SeckillDetailVo> getSeckillDetail({ required int id, bool loading = true }) async {
    return SeckillDetailVo.fromJson(await HttpUtil.instance.get('/seckill/holder/seckills/$id', loading: loading));
  }
  
  /// 获取商城订单列表
  static Future<StoreOrderListVo> getStoreOrderList({ required int status, required int pickType, int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'status': status,
      'pick_type': pickType,
    };
    return StoreOrderListVo.fromJson(await HttpUtil.instance.get('/order/orders', data: param, loading: loading));
  }
  
  /// 生成抢购订单
  static Future<SubmitSeckillOrderVo?> submitSeckillOrder({ required int productId, required int holderId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'product_id': productId,
      'holder_id': holderId,
      'quantity': 1
    };
    var res = await HttpUtil.instance.post('/seckill/order/orders', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return SubmitSeckillOrderVo.fromJson(res);
  }
  
  // /// 获取抢购订单详情
  // static Future<SeckillOrderDetailVo> getSeckillOrderDetail({ required int orderId, bool loading = true }) async {
  //   return SeckillOrderDetailVo.fromJson(await HttpUtil.instance.get('/seckill/order/orders/$orderId', loading: loading));
  // }

  /// 获取盲盒
  static Future<BlindBoxOrderDetailVo> getSeckillOrderDetail({ required int orderId, bool loading = true }) async {
    return BlindBoxOrderDetailVo.fromJson(await HttpUtil.instance.get('/blindbox/order/orders/$orderId', loading: loading));
  }

  /// 获取盲盒订单列表
  static Future<BlindBoxOrderListVo> getBlindBoxOrderList({ required int status, int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'status': status,
      'include': 'packages'
    };
    return BlindBoxOrderListVo.fromJson(await HttpUtil.instance.get('/blindbox/order/orders', data: param, loading: loading));
  }
  
  /// 抢购订单确认付款
  static Future<bool> seckillOrderConfirmPayment({ required int orderId, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/seckill/order/payments/$orderId', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 抢购订单确认收款
  static Future<bool> seckillOrderConfirmReceipt({ required int orderId, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/seckill/order/receives/$orderId', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 我的商品列表（抢购商品）
  static Future<SeckillMyCommodityListVo> getMyCommodityList({ int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return SeckillMyCommodityListVo.fromJson(await HttpUtil.instance.get('/seckill/space/holders', data: param, loading: loading));
  }
  
  /// 获取置换列表
  static Future<DisplacementListVo> getDisplacementList({ required int productId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'product_id': productId
    };
    return DisplacementListVo.fromJson(await HttpUtil.instance.get('/seckill/product/products', data: param, loading: loading));
  }

  /// 确认置换
  static Future<EntrustVo?> onfirmEntrust({ required int productId, required int holderId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'product_id': productId,
      'holder_id': holderId,
    };
    var res = await HttpUtil.instance.post('/seckill/substitute/orders', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return EntrustVo.fromJson(res);
  }

  /// 微信支付
  static Future<WxPayVo?> wxPay({ required String orderSn, int orderType = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_sn': orderSn,
      'order_type': orderType,
    };
    var res = await HttpUtil.instance.get('/pay/wechat/app', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return WxPayVo.fromJson(res);
  }

  /// 支付宝支付
  static Future<AliPayVo?> aliPay({ required String orderSn, int orderType = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_sn': orderSn,
      'order_type': orderType,
    };
    var res = await HttpUtil.instance.get('/pay/alipay/app', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return AliPayVo.fromJson(res);
  }
  
  /// 银联支付
  static Future<bool> bankPay({ required String orderSn, required int fastPaymentId, required String password, int orderType = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_sn': orderSn,
      'order_type': orderType,
      'payment_id': fastPaymentId,
      'password': password,
    };
    var res = await HttpUtil.instance.get('/pay/joinpay/fastpay/pay', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 商城订单取消订单
  static Future<bool> storeOrderCancel({ required int orderId, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/order/cancel/$orderId', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 商城订单确认收货
  static Future<bool> storeOrderReceive({ required int orderId, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/order/receive/$orderId', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 获取空间统计
  static Future<TeamSpacesVo> getTeamSpaces({ bool loading = true }) async {
    return TeamSpacesVo.fromJson(await HttpUtil.instance.get('/team/spaces', loading: loading));
  }

  /// 获取团队表现
  static Future<TeamMembersVo> getTeamMembers({ int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return TeamMembersVo.fromJson(await HttpUtil.instance.get('/team/members', data: param, loading: loading));
  }

  /// 获取置换价格
  static Future<SeckillSubstitutePricesVo> getSeckillSubstitutePrices({ required int holderProductId, required int substituteProductId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'holder_product_id': holderProductId,
      'substitute_product_id': substituteProductId,
    };
    return SeckillSubstitutePricesVo.fromJson(await HttpUtil.instance.get('/seckill/substitute/prices', data: param, loading: loading));
  }

  /// 注销账号
  static Future<bool> cancelAccount({ bool loading = true }) async {
    var res = await HttpUtil.instance.del('/user/users/1', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 获取提现记录
  static Future<WithdrawalListVo> getWithdrawalRecordList({ int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return WithdrawalListVo.fromJson(await HttpUtil.instance.get('/finance/withdraws', data: param, loading: loading));
  }
  
  /// 申请提现
  static Future<bool> withdrawal({ required String amount, required String verificationCode, required int paymentId, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'amount': amount,
      'verification_code': verificationCode,
      'payment_id': paymentId,
      'verification_key': verificationKey,
    };
    var res = await HttpUtil.instance.post('/finance/withdraws', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 一键回收
  static Future<bool> seckillRecovery({ bool loading = true }) async {
    var res = await HttpUtil.instance.post('/seckill/recovery/products', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 获取回收列表
  static Future<SeckillRecoveryVo> getSeckillRecoveryList({ required String period, int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'period': period
    };
    return SeckillRecoveryVo.fromJson(await HttpUtil.instance.get('/seckill/recovery/products', data: param, loading: loading));
  }
  
  /// 获取置换商品详情
  static Future<SeckillHolderProductsVo> getSeckillHolderProductsDetail({ required int productId, bool loading = true }) async {
    return SeckillHolderProductsVo.fromJson(await HttpUtil.instance.get('/seckill/holder/products/$productId', loading: loading));
  }
  
  /// 获取赠品列表
  static Future<GiftListVo> getGiftList({ required int page, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return GiftListVo.fromJson(await HttpUtil.instance.get('/gift/holder/products', data: param, loading: loading));
  }
  
  /// 提交赠品订单
  static Future<bool> submitGiftOrder({ required int holderId, required int addressId, required int quantity, String expressId = '10001', bool loading = true }) async {
    Map<String, dynamic> param = {
      'holder_id': holderId,
      'address_id': addressId,
      'quantity': quantity,
      'express_id': expressId
    };
    var res = await HttpUtil.instance.post('/gift/order/orders', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 获取赠品订单列表
  static Future<GiftOrderListVo> getGitfOrderList({ int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return GiftOrderListVo.fromJson(await HttpUtil.instance.get('/gift/order/orders', data: param, loading: loading));
  }
  
  /// 获取赠品订单详情
  static Future<GiftOrderDetailVo> getGiftOrderDetail({ required int orderId, bool loading = true }) async {
    return GiftOrderDetailVo.fromJson(await HttpUtil.instance.get('/gift/order/orders/$orderId', loading: loading));
  }

  /// 获取快捷支付系统银行卡及认证信息
  static Future<SystemBankAndAuthListVo> getSystemBankAndAuthList({ int channel = 0, bool loading = true }) async {
    Map<String, dynamic> param = {
      'channel': channel
    };
    return SystemBankAndAuthListVo.fromJson(await HttpUtil.instance.get('/system/banks', data: param, loading: loading));
  }
  
  /// 获取快捷支付系统银行卡及认证信息
  static Future<bool> getPaySmsCode({ 
    required int identityType, 
    required String identityNumber, 
    required String payerName,
    required String cardNumber,
    required String mobile,
    required int bankId, 
    bool loading = true }) async {
    Map<String, dynamic> param = {
      'identity_type': identityType,
      'identity_number': identityNumber,
      'payer_name': payerName,
      'card_number': cardNumber,
      'mobile': mobile,
      'bank_id': bankId,
    };
    var res = await HttpUtil.instance.get('/pay/joinpay/fastpay/sms', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 解绑支付银行卡
  static Future<bool> unboundAddPayBank({ required int paymentId, required String verificationCode, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'verification_code': verificationCode,
      'verification_key': verificationKey,
    };
    var res = await HttpUtil.instance.del('/user/payments/$paymentId', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  // /// 获取支付银行卡列表
  // static Future<PayBankListVo> getPayBankList({ bool loading = true }) async {
  //   return PayBankListVo.fromJson(await HttpUtil.instance.get('/pay/fastpay/list', loading: loading));
  // }
  
  /// 修改支付密码
  static Future<bool> updatePayPassword({ required String verificationCode, required String password, required String verificationKey, bool loading = true }) async {
    Map<String, dynamic> param = {
      'verification_code': verificationCode,
      'password': password,
      'verification_key': verificationKey,
    };
    var res = await HttpUtil.instance.post('/user/pay/passwords', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// --------------------
  /// 获取抢购活动商品列表
  static Future<SeckillActivityProductsVo> getSeckillActivityProductsList({ int page = 1, bool loading = true}) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return SeckillActivityProductsVo.fromJson(await HttpUtil.instance.get('/seckill/space/products', data: param, loading: loading));
  }


  /// 获取抢购活动商品详情
  static Future<SeckillActivityProductsDetailVo> getSeckillActivityProductsDetail({ required int id, bool loading = true }) async {
    return SeckillActivityProductsDetailVo.fromJson(await HttpUtil.instance.get('/seckill/space/products/$id', loading: loading));
  }

  /// 生成抢购活动订单
  static Future<CreateSeckillOrderVo?> createSeckillOrder({ required int productId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'id': productId
    };
    var res = await HttpUtil.instance.post('/seckill/order/orders', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return CreateSeckillOrderVo.fromJson(res);
  }

  /// 降价
  static Future<bool> priceReduction({ required int id, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/seckill/space/cutprice/$id', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 获取我的商品详情
  static Future<SeckillHolderProductsDetailVo> getMyCommodityDetail({ required int id, bool loading = true }) async {
    return SeckillHolderProductsDetailVo.fromJson(await HttpUtil.instance.get('/seckill/space/holders/$id', loading: loading));
  }

  /// 取消抢购订单
  static Future<bool> closeSeckillOrder({ required int id, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/blindbox/order/close/$id', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 确认提货
  static Future<bool> confirmDelivery({ required int orderId, required int addressId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_id': orderId,
      'address_id': addressId,
    };
    var res = await HttpUtil.instance.post('/seckill/order/pickup', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 确认收货
  static Future<bool> confirmReceipt({ required int orderId, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/blindbox/order/receive/$orderId', loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }
  
  /// 上传用户定位
  static Future<bool> userLocations({  required String address, 
                                       required String latLng,
                                       required String country,
                                       required String province,
                                       required String city,
                                       required String cityCode,
                                       required String adCode,
                                       required String district,
                                       required String poiName,
                                       required String street,
                                       bool loading = true }) async {
    Map<String, dynamic> param = {
      'address': address,
      'latLng': latLng,
      'country': country,
      'province': province,
      'city': city,
      'cityCode': cityCode,
      'adCode': adCode,
      'district': district,
      'poiName': poiName,
      'street': street,
    };
    var res = await HttpUtil.instance.post('/user/locations', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 抢购、提现银行卡获取验证码
  static Future<PayVerificationVo> getPayVerification({
    int type = 1,
    required String accountName,
    required String cardNumber,
    required int bankId,
    int identityType = 1,
    required String identityNumber,
    required String mobile,
    bool loading = true
  }) async {
    Map<String, dynamic> param = {
      'type': type,
      'account_name': accountName,
      'card_number': cardNumber,
      'bank_id': bankId,
      'identity_type': identityType,
      'identity_number': identityNumber,
      'mobile': mobile,
    };
    return PayVerificationVo.fromJson(await HttpUtil.instance.post('/pay/verification', data: param, loading: loading));
  }

  /// 修改抢购订单地址
  static Future<bool> changeOrderAddress({required int addressId, required int orderId, bool loading = false}) async {
    Map<String, dynamic> param = {
      'address_id': addressId,
      'order_id': orderId,
    };
    var res = await HttpUtil.instance.post('/seckill/order/addresses', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 获取广告
  static Future<AdvertVo> getAdvert({ bool loading = false}) async {
    return AdvertVo.fromJson(await HttpUtil.instance.get('/advert', loading: loading));
  }

  /// 转卖
  static Future<bool> seckillSpacesell({ required int holderId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'holder_id': holderId
    };
    var res = await HttpUtil.instance.post('/seckill/space/sell', data: param, loading: loading);
    if (res == null) {
      return false;
    }
    return true;
  }

  /// 获取盲盒列表
  static Future<BlindboxActivityProductsVo> getBlindboxActivityProducts({int page = 1, bool loading = true}) async {
    Map<String, dynamic> param = {
      'page': page
    };
    return BlindboxActivityProductsVo.fromJson(await HttpUtil.instance.get('/blindbox/package/packages', data: param, loading: loading));
  }
  
  /// 获取盲盒详情
  static Future<BlindboxProductsDetailVo> getBlindboxProductDetail({ required int id, bool loading = true}) async {
    return BlindboxProductsDetailVo.fromJson(await HttpUtil.instance.get('/blindbox/package/packages/$id', loading: loading));
  }

  /// 活动规则
  static Future<BlindboxActivitiesVo> getBlindboxActivity({ bool loading = true}) async {
    return BlindboxActivitiesVo.fromJson(await HttpUtil.instance.get('/blindbox/activity/activities', loading: loading));
  }
  
  /// 提交盲盒订单
  static Future<BlindBoxSubmitOrderVo> submitBlindBoxOrder({ required int id, required int addressId, bool loading = true}) async {
    Map<String, dynamic> param = {
      'id': id,
      'address_id': addressId,
    };
    return BlindBoxSubmitOrderVo.fromJson(await HttpUtil.instance.post('/blindbox/order/orders', data: param, loading: loading));
  }

  /// 上传图片
  static Future<UploadImageVo> uploadImage(FormData formdata) async {
    return UploadImageVo.fromJson(await HttpUtil().formPost('/system/upload', data: formdata));
  }

  /// 获取实名认证信息
  static Future<IdentitiesVo> getUserIdentities() async {
    return IdentitiesVo.fromJson(await HttpUtil().get('/user/identities'));
  }
  
  /// 获取积分表
  static Future<IntegralListVo> getIntegrals({required String createdAt, int type = 1, int page = 1, bool loading = true}) async {
    Map<String, dynamic> param = {
      'created_at': createdAt,
      'type': type,
      'page': page
    };
    return IntegralListVo.fromJson(await HttpUtil().get('/user/integrals', data: param, loading: loading));
  }
  
  /// 获取积分详情
  static Future<IntegralDetailVo> getIntegralDetail({required int id, bool loading = true}) async {
    return IntegralDetailVo.fromJson(await HttpUtil().get('/user/integrals/$id', loading: loading));
  }

  /// 签到
  static Future<SignVo> userSign({ bool loading = true }) async {
    return SignVo.fromJson(await HttpUtil.instance.post('/user/signs', loading: loading));
  }
  
  /// 签到记录
  static Future<SignRecordVo> getUserSignRecord({ bool loading = true }) async {
    return SignRecordVo.fromJson(await HttpUtil.instance.get('/user/signs', loading: loading));
  }
  
  /// 获取公告
  static Future<AnnouncementsVo?> getAnnouncements({ int type = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'type': type,
      'latest': 1
    };
    var res = await HttpUtil.instance.get('/system/announcements', data: param, loading: loading);
    if (res is String) {
      return null;
    }
    return AnnouncementsVo.fromJson(res);
  }

  /// 获取物流信息
  static Future<LogisticsVo> getLogistics({ required String companyCode, required String trackingNumber, bool loading = true }) async {
    Map<String, dynamic> param = {
      'company_code': companyCode,
      'tracking_number': trackingNumber
    };
    return LogisticsVo.fromJson(await HttpUtil.instance.get('/logistics/tracking', data: param, loading: loading));
  }

  /// 申请赎回
  static Future<bool> redeem({ required String orderSn, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_sn': orderSn
    };
    var res = await HttpUtil.instance.post('/pay/refund', data: param, loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }
  
  /// 继续预约
  static Future<bool> continueAppointment({ required String orderSn, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/blindbox/order/renewals/$orderSn', loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }
  
  /// 获取门店列表
  static Future<StoreListVo> getStores({ String title = '', int page = 1, bool loading = true }) async {
    Map<String, dynamic> param = {
      'page': page,
      'title': title,
    };
    return StoreListVo.fromJson(await HttpUtil.instance.get('/store/stores', data: param, loading: loading));
  }
  
  /// 查询支付状态
  /// order_sn 订单号
  /// refund 0 选填，退款则传1
  /// order_type 选填 默认1 订单类型 1普通订单，2置换订单
  static Future<OrderPayStatusVo> getOrderPayStatus({ required String orderSn,  int orderType = 1, int refund = 0, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_sn': orderSn,
      'order_type': orderType,
      'refund': refund,
    };
    return OrderPayStatusVo.fromJson(await HttpUtil.instance.get('/pay/status', data: param, loading: loading));
  }
  
  /// 获取门店可预约时间列表
  static Future<StoreTimeListVo> getStoreTimeList({ required int id, bool loading = true }) async {
    return StoreTimeListVo.fromJson(await HttpUtil.instance.get('/store/stores/$id', loading: loading));
  }

  /// 预约门店
  static Future<bool> submitStoreMark({ required int orderId, required int storeId, required String pickTime, bool loading = true }) async {
    Map<String, dynamic> param = {
      'order_id': orderId,
      'store_id': storeId,
      'pick_time': pickTime,
    };
    var res = await HttpUtil.instance.post('/store/orders', data: param, loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }

  /// 获取接受人列表
  static Future<ReceiveUserListVo?> getReceiveUserList({ required String mobile, bool loading = true }) async {
    Map<String, dynamic> param = {
      'mobile': mobile
    };
    var res = await HttpUtil.instance.get('/user/users', data: param, loading: loading);
    if (res == null) {
      return null;
    }
    return ReceiveUserListVo.fromJson(res);
  }

  /// 确认赠送
  static Future<bool> confirmGift({ required String receiver, required int orderId, bool loading = true }) async {
    Map<String, dynamic> param = {
      'receiver': receiver,
      'order_id': orderId
    };
    var res = await HttpUtil.instance.post('/order/transfer', data: param, loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }
  
  /// 扫码获取核销商品数据
  static Future<WriteoffVo> getWriteoffData({ required String code, bool loading = true }) async {
    return WriteoffVo.fromJson(await HttpUtil.instance.get('/store/writeoff/$code', loading: loading));
  }

  /// 扫码核销商品数据（商品）
  static Future<MsgVo?> writeoffData({ required String code, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/store/writeoff/$code', loading: loading);
    if (res is String) {
      return null;
    }
    return MsgVo.fromJson(res);
  }
  
  /// 核销商品数据（转款）
  static Future<MsgVo?> checkoff({ required int id, bool loading = true }) async {
    var res = await HttpUtil.instance.put('/order/checkoff/$id', loading: loading);
    if (res is String) {
      return null;
    }
    return MsgVo.fromJson(res);
  }

  /// 一键核销
  static Future<bool> orderCheckoff({ bool loading = true }) async {
    var res = await HttpUtil.instance.post('/order/checkoff', loading: loading);
    if (res != null) {
      return true;
    }
    return false;
  }

}

